package c.x.jy.service.service.impl;

import c.x.jy.common.utils.Constant;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import c.x.jy.common.utils.PageUtils;
import c.x.jy.common.utils.Query;

import c.x.jy.dao.dao.SysMenuDao;
import c.x.jy.dao.entity.SysMenuEntity;
import c.x.jy.service.service.SysMenuService;
import org.apache.commons.lang3.StringUtils;


@Service("sysMenuService")
public class SysMenuServiceImpl extends ServiceImpl<SysMenuDao, SysMenuEntity> implements SysMenuService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        	QueryWrapper<SysMenuEntity> query= 	 new QueryWrapper<SysMenuEntity>() ;
    	if(params.get("searchKey")!=null&&params.get("searchValue")!=null&&!StringUtils.isEmpty(params.get("searchKey").toString())&&!StringUtils.isEmpty(params.get("searchValue").toString()))
    	    query.eq(  params.get("searchKey").toString(), params.get("searchValue"));
        if(params.get("businessId")!=null) 	query.eq("business_id", params.get("businessId"));
        IPage<SysMenuEntity> page = this.page(
                new Query<SysMenuEntity>().getPage(params),
                 query
        );

        return new PageUtils(page);
    }

    @Override
    public List<SysMenuEntity> findByRoleCodes(Set<Long> roleids, Integer... type) {

        return this.baseMapper.findByRoleCodes(roleids, type==null?null: Arrays.asList(type));
    }

    @Override
    public List<SysMenuEntity> findAlls() {

        QueryWrapper<SysMenuEntity> query=new QueryWrapper<>();
        query.in ("type", new Integer [] {Constant.MenuType.MENU.getValue(),Constant.MenuType.CATALOG.getValue()} );
        return this.baseMapper.selectList (query);
    }


}
